<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>个人中心</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css" />
    <link rel="stylesheet" href="../plugins/elementui/index.css" />
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right"><a id="edit" class="icon-zhen" style="display:block;" onclick="edit()" >编辑</a><a id="preserved" class="icon-zhen" style="display: none" @click="preserved">保存</a></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="form-info">
            <div class="info-title">
                <span class="name">个人中心</span>
            </div>
            <form class="info-form">
                <div class="input-row">
                    <label>用户名</label>
                    <input id="memberName" v-model="member.name" type="text" class="input-clear" readonly placeholder="请输入姓名">
                </div>
                <div class="input-row single-radio">
                    <label class="radio-title">性别</label>
                    <div class="radio-list">
                        <div class="radio">
                            <input v-model="member.sex" disabled id="item1" type="radio" name="sex" value="1">
                            <label for="item1" ></label>
                            <span>男</span>
                        </div>
                        <div class="radio">
                            <input v-model="member.sex" disabled id="item2" type="radio" name="sex" value="2">
                            <label for="item2"></label>
                            <span>女</span>
                        </div>
                    </div>
                </div>
                <div class="input-row">
                    <label>联系方式</label>
                    <input id="phoneNumber" v-model="member.phoneNumber" type="text" readonly class="input-clear">
                </div>
                <div class="input-row">
                    <label>身份证号</label>
                    <input id="idCard" v-model="member.idCard" type="text" class="input-clear" readonly placeholder="请输入身份证号">
                </div>
                <div class="input-row">
                    <label>邮箱</label>
                    <input id="email" v-model="member.email" type="text" class="input-clear" readonly placeholder="请输入邮箱">
                </div>
                <div class="date">
                    <label>出生日期</label>
                    <!--<i class="icon-date" class="picktime"></i>-->
                    <input id="birthday" v-model="member.birthday" type="text" class="picktime" disabled>
                </div>
            </form>
        </div>
    </div>
</div>
    <!-- 页面 css js -->
    <!-- <script src="health-index.js"></script> -->
<script>
    //点击编辑按钮事件
    function edit() {
        //隐藏编辑按钮展示保存按钮
        document.querySelector("#edit").style.display='none';
        document.querySelector("#preserved").style.display='block';
        document.getElementById("memberName").removeAttribute("readonly");
        document.getElementById("phoneNumber").removeAttribute("readonly");
        document.getElementById("idCard").removeAttribute("readonly");
        document.getElementById("email").removeAttribute("readonly");
        document.getElementById("birthday").removeAttribute("disabled");
    }
</script>
<script>
     var vue = new Vue({
         el: '#app',
         data: {
             member: {}
         },
         created() {
             let telephone = this.getCookie("member_telephone");
             this.getMember(telephone);
         },
         methods: {
             getMember(telephone) {
                 axios.post("/member/findByTelephone.do?telephone=" + telephone).then((resp) => {
                     if (resp.data.flag) {
                         this.member = resp.data.data;
                     } else {
                         this.$message.error(resp.data.message);
                     }
                 });
             },
             //获取cookie
             getCookie(cname) {
                 var name = cname + "=";
                 var ca = document.cookie.split(';');
                 console.log("获取cookie,现在循环")
                 for (var i = 0; i < ca.length; i++) {
                     var c = ca[i];
                     console.log(c)
                     while (c.charAt(0) == ' ') c = c.substring(1);
                     if (c.indexOf(name) != -1) {
                         return c.substring(name.length, c.length);
                     }
                 }
                 return "";
             },
             preserved() {
                 axios.post("/member/edit.do", this.member).then((resp) => {
                     if (resp.data.flag) {
                         document.querySelector("#edit").style.display = 'block';
                         document.querySelector("#preserved").style.display = 'none';
                         document.getElementById("memberName").setAttribute("readonly", true);
                         document.getElementById("phoneNumber").setAttribute("readonly", true);
                         document.getElementById("idCard").setAttribute("readonly", true);
                         document.getElementById("email").setAttribute("readonly", true);
                         document.getElementById("birthday").setAttribute("disabled", false);
                     } else {
                         axios.post("/member/findByTelephone.do?telephone=" + telephone).then((resp) => {
                             this.member = resp.data.data;
                         });
                         document.querySelector("#edit").style.display = 'block';
                         document.querySelector("#preserved").style.display = 'none';
                         document.getElementById("memberName").setAttribute("readonly", true);
                         document.getElementById("phoneNumber").setAttribute("readonly", true);
                         document.getElementById("idCard").setAttribute("readonly", true);
                         document.getElementById("email").setAttribute("readonly", true);
                         document.getElementById("birthday").setAttribute("disabled", false);
                         alert("修改用户信息失败");
                     }
                 });
             }
         }
     });
</script>
<script>
    //日期控件
    var calendar = new datePicker();
    calendar.init({
        'trigger': '.picktime',/*按钮选择器，用于触发弹出插件*/
        'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
        'onSubmit': function() { /*确认时触发事件*/
            //var theSelectData = calendar.value;
        },
        'onClose': function() { /*取消时触发事件*/ }
    });
</script>
</body>
</html>